<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
abstract  class BaseSiteController extends CController
{
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
	public $activemenu='';
	public function init()
	{
		if (isset($_REQUEST['lang'])){
       		$lang = $_REQUEST['lang'];
			Yii::app()->language = $lang;
       }else{
       		Yii::app()->language = Yii::app()->params['language_default'];
       }
	}
	public function createUrl($route,$params=array(),$ampersand='&')
	{
		if($route==='')
			$route=$this->getId().'/'.$this->getAction()->getId();
		else if(strpos($route,'/')===false)
			$route=$this->getId().'/'.$route;
		if($route[0]!=='/' && ($module=$this->getModule())!==null)
			$route=$module->getId().'/'.$route;
		//if(isset($_GET['lang']) && $_GET['lang']!=Yii::app()->params['language_default']){
		if(Yii::app()->params['multilang']){
			if(isset($_GET['lang']) && $_GET['lang']!=''){
				$params['lang']=$_GET['lang'];
			}else{
				$params['lang']=Yii::app()->params['language_default'];
			}
		}
		return Yii::app()->createUrl(trim($route,'/'),$params,$ampersand);
	}
}